package com.jinyou.chengfengshop.adapter;

import com.jinyou.chengfengshop.R;
import com.jinyou.chengfengshop.activity.AddOrderPhotoActivity;
import com.jinyou.chengfengshop.bean.LineBean;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.io.Serializable;
import java.util.List;

/**
 * Created by zhuzhiqiang on 2018/9/23.
 */

public class AddressAdapter extends RecyclerView.Adapter<AddressAdapter.ViewHolder> {


    private List<LineBean> lineBean;
    private Context con;

    public AddressAdapter(Context conn,List<LineBean> lineBean){
        this.lineBean = lineBean;
        this.con = conn;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.addorder_list_item, parent, false);
        ViewHolder vh = new ViewHolder(view);
        return vh;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.mTextView.setText(lineBean.get(position).getName());
        holder.itemView.setTag(lineBean.get(position).getNameSn());
        holder.mTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent mIntent = new Intent(con, AddOrderPhotoActivity.class);
                mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                mIntent.putExtra("INFOB", (Serializable) lineBean.get(position).getInfob());
                con.startActivity(mIntent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return lineBean.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder {
        public TextView mTextView;

        public ViewHolder(View view) {
            super(view);
            mTextView = (TextView) view.findViewById(R.id.add_tv);
        }
    }
}
